from openpyxl import load_workbook


wb = load_workbook('files/p1.xlsx')
sheet = wb.worksheets[0]

'''
# 获取第n行第n列的单元格
cell = sheet.cell(1,1)
print(cell.value)
print(cell.style)
print(cell.font)
print(cell.alignment)
'''

'''
# 获取某个单元格
c1 = sheet['A2']
print(c1)
print(c1.value)
'''

'''
# 获取第n行所有的单元格
print(sheet[1])
for cell in sheet[1]:
    print(cell.value)
'''

'''
# 获取所有行的单元格（获取某一列）
for row in sheet.rows:
    print(row[0].value) # 第一列的数据
'''

# 获取所有列的单元格
for col in sheet.columns:
    print(col[1].value)  # 第二行的数据



# 合并的单元格要注意，值会是空
sheet2 = wb.worksheets[1]
c1 = sheet2.cell(1,1)
print(c1)   # <Cell 'info'.A1>
print(c1.value) # 用户信息


c2 = sheet2.cell(1,2)
print(c2,c2.value)  # <MergedCell 'info'.B1> None

for row in sheet2.rows:
    print(row)